/**
 * Created by Scor on 2015/9/1.
 */
//AngularJS 控制器
grApp.controller('CollectCtrl',['$scope',
    '$http',
    'toaster',
    function($scope,$http,toaster){
        var loadingModal = angular.element("#icon-alert");
        loadingModal.modal();
    //页面初始化载入顺序事件
        $http.post('/user/center/getUserCollect').success(function(data, status, headers, config)
        {
            loadingModal.modal('close');
            $scope.collects=data;
            angular.forEach($scope.collects,function(data,index,array){
                $scope.collects[index].fileurl=JSON.parse(data.picurlarray)[0];
            });
            //console.log(data);
        }).error(function(data, status, headers, config) {
        });
        $scope.removeCollect=function(index,objectId){
            loadingModal.modal();
            var objectId=parseInt(objectId);
            $http({
                method: 'GET',
                url: '/user/center/removeUserCollect',
                params:{objectId:objectId}
            }).success(function(data) {
                loadingModal.modal('close');
                if(data.code==0){
                    toaster.success('删除成功');
                    $scope.collects.splice(index,1);
                }
                $scope.collects=$scope.collects;

            }).error(function(data) {
                loadingModal.modal('close');
            });
        };
}]);